package solution;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-19
 * Time: 16:16
 */

//https://leetcode.cn/problems/length-of-last-word/submissions/396285604/
class Solution2 {
    public int lengthOfLastWord(String s) {
        int ls = s.length() - 1;
        int count = 0;
        while (s.charAt(ls) == ' ') {
            ls--;
        }
        while (ls >= 0 && s.charAt(ls) != ' ') {
            count++;
            ls--;
        }
        return count;
    }
}
